package com.kyin.demo1;

public class MyDemo01 {

    ThreadLocal<String> t1 = new ThreadLocal<>();

    //变量
    private String content;

    private String getContent() {
        //return content;
        return t1.get();
    }

    public void setContent(String content) {
        //this.content = content;
        //变量content绑定到当前线程
        t1.set(content);
    }


    public static void main(String[] args) {
        MyDemo01 demo = new MyDemo01();

        for (int i = 0; i < 5; i++) {
            new Thread(() -> {
                demo.setContent(Thread.currentThread().getName() + "的数据");
                System.out.println("------------------------");
                System.out.println(Thread.currentThread().getName() + "--->" + demo.getContent());
            }, "线程" + i).start();
        }
    }
}
